<?php

namespace app\model\office;

use app\model\BaseModel;
use think\model\concern\SoftDelete;

class OfficeUser extends BaseModel
{
    use SoftDelete;

    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $table = 'free_office_user';

    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = '0000-00-00 00:00:00';


    public function majors(){
        return $this->hasOne(OfficeMajor::class,'id','major_id');
    }

    public function searchMajorIdAttr($query, $value)
    {
        if ($value) $query->where('major_id', $value);
    }
    public function searchSexAttr($query, $value)
    {
        if ($value) $query->where('sex', $value);
    }
    public function searchEnterBatchAttr($query, $value)
    {
        if ($value) $query->where('enter_batch', $value);
    }
    public function searchEnterTypeAttr($query, $value)
    {
        if ($value) $query->where('enter_type', $value);
    }
    public function searchNameAttr($query, $value)
    {
        $query->where('name', 'like', '%' . $value . '%');
    }
    public function searchIdcardAttr($query, $value)
    {
        $query->where('idcard', 'like', '%' . $value . '%');
    }
    public function searchPhoneAttr($query, $value)
    {
        $query->where('phone', 'like', '%' . $value . '%');
    }
    public function searchExamNumberAttr($query, $value)
    {
        $query->where('exam_number', 'like', '%' . $value . '%');
    }
    public function searchStudentNumberAttr($query, $value)
    {
        $query->where('student_number', 'like', '%' . $value . '%');
    }



    //-----------------------------------------api----------------------------------------------
    public function class(){
        return $this->hasMany(OfficeClass::class,'major_id','major_id');
    }
}